package com.han.fu.api.business.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.han.fu.api.business.model.ao.PartakeAddAo;
import com.han.fu.api.business.model.ao.PartakeDeleteAo;
import com.han.fu.api.business.model.ao.PartakePageAo;
import com.han.fu.api.business.model.ao.PartakeUpdateAo;
import com.han.fu.api.business.model.vo.PartakeInfoVo;
import com.han.fu.api.business.model.vo.PartakeVo;
import com.han.fu.api.business.service.IPartakeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 参与接口
 *
 * @author: star
 * @date: 2021-08-05
 */
@RestController
public class PartakeController {

    @Autowired
    IPartakeService iPartakeService;

    /**
     * 参与分页查询
     *
     * @param ao 分页查询条件
     * @return Page<PartakeVo> 分页数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/partake/page")
    public Page<PartakeVo> queryPartakePage(@Validated @RequestBody PartakePageAo ao) {
        return iPartakeService.queryPartakePage(ao);
    }

    /**
     * 参与明细查询
     *
     * @param id 主键
     * @return PartakeInfoVo 明细
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @GetMapping("/partake/detail")
    public PartakeInfoVo queryPartakeDetail(@NotNull(message = "ID不能为空") @RequestParam String id) {
        return iPartakeService.queryPartakeDetail(id);
    }

    /**
     * 参与新增数据
     *
     * @param ao 数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/partake/add")
    public void addPartake(@Validated @RequestBody PartakeAddAo ao) {
        iPartakeService.addPartake(ao);
    }

    /**
     * 参与修改数据
     *
     * @param ao 数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/partake/update")
    public void updatePartake(@Validated @RequestBody PartakeUpdateAo ao) {
        iPartakeService.updatePartake(ao);
    }

    /**
     * 参与删除数据
     *
     * @param ao 数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/partake/delete")
    public void deletePartake(@Validated @RequestBody PartakeDeleteAo ao) {
        iPartakeService.deletePartake(ao);
    }

}